﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Sistema
{
    public partial class FrmCadLogin : Form
    {
        public FrmCadLogin()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {



                MySqlCommand SelectCommand = new MySqlCommand("select * from mydb.usuario where user='" + this.cmpadminuser.Text + "' and senha='" + this.cmpadminsenha.Text + "';", Conexao.Conn);
                MySqlDataReader result;
                Conexao.Conn.Open();
                result = SelectCommand.ExecuteReader();

                int count = 0;
                while (result.Read())
                {
                    count++;
                }
                if (count == 1)
                {
                    result.Close();
                    MySqlCommand sql = new MySqlCommand("insert into mydb.usuario(user,senha) values('" + this.cmpnovouser.Text + "','" + this.cmpnovosenha.Text + "')", Conexao.Conn);
                    sql.ExecuteNonQuery();
                    Conexao.Conn.Close();

                    MessageBox.Show("Usuário Cadastrado com Sucesso!");
                }

                else
                    MessageBox.Show("Usuario e/ou senha de Administrador incorretos. Por favor tente novamente");
                Conexao.Conn.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
